import { defineStore } from "pinia";
import router from "@/router";

export const useUserStore = defineStore("user", {
  state: () => ({
    isLoggedIn: false,
    user: null,
  }),
  actions: {
    loginWithEmailAndPassword(email, password, username, id) {
      this.user = { email, password, username, id };
      this.isLoggedIn = true;
      router.push({ name: "home" });
    },
    logout() {
      this.isLoggedIn = false;
      router.push({ name: "home" });
    },
    refreshPage(email, username, id) {
      this.user = { email, username, id };
      this.isLoggedIn = true;
    },
  },
});
